(function(){
	"use strict";
	
	var $userNameEL,
		$lastLoginTimeEL,
		$lastLoginIpEL,
		$weatherEL,
		$onlineUserEL,
		$totalAccountEL,
		$cpuPayloadEL,
		$memoryPayloadEL
	;
	
	
	$(function(){
		$userNameEL=$("#userNameEL");
		$lastLoginIpEL=$("#lastLoginIpEL");
		$lastLoginTimeEL=$("#lastLoginTimeEL");
		
		$onlineUserEL=$("#onlineUserEL");
		$totalAccountEL=$("#totalAccountEL");
		$cpuPayloadEL=$("#cpuPayloadEL");
		$memoryPayloadEL=$("#memoryPayloadEL");
		
		paintLoginInfo();
		paintSystemInfo();
	});
	
	var paintLoginInfo=function(){
		var uc=JSON.parse(sessionStorage.getItem("currentUser"));
		//console.log(uc);
		$userNameEL.text(uc.name);
		//是否是第一次登录
		if(uc.lastLoginTime){
			$lastLoginIpEL.text(uc.lastLoginIP);
			$lastLoginTimeEL.text(Date.format(uc.lastLoginTime));
		}else{
			//第一次登录
			$("#tipBox").remove();
		}
		
	};
	
	var paintSystemInfo=function(){
		var url="/api/system/statistics";
		$.get(url,function(resp){
			var result=resp.data;
			//console.log(result);
			if(resp.code==="ok"){
				$totalAccountEL.text(result.totalAccount);
				$cpuPayloadEL.text(result.cpuPayload);
				$memoryPayloadEL.text(result.memoryPayload);
				$onlineUserEL.text(result.onlineUsers);
			}else{
				toast(resp.message);
			}
		});
		
	};
	
	
	
})();
